from typing import List

class Solution:
    def maximumRows(self, matrix: List[List[int]], numSelect: int) -> int:
        m, n = len(matrix), len(matrix[0])
        if numSelect < n:
            col_sum = [sum([ r[i] for r in matrix]) for i in range(n)]
            row_sum = [sum(r) for r in matrix]

            col_sum_sorted = sorted(enumerate(col_sum), key=lambda x: x[1], reverse=True)
            selected_sum = [ sum([ r[c[0]] for c in col_sum_sorted[:numSelect]]) for r in matrix ]
            return sum([ row_sum[i]==selected_sum[i] for i in range(m)])

        return m

if __name__ == '__main__':
    matrix = [[0,0,0],[1,0,1],[0,1,1],[0,0,1]]
    numSelect = 2
    s = Solution()
    res = s.maximumRows(matrix, numSelect)
    print(res)